/* Copyright (c) 2009 Christopher Humphries, Maxime Simon
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package history;

/**
 * @author Humphries Christopher - Simon Maxime
 * 
 */
public class Originator {

    private String m_before;
    private String m_after;
    private int m_start;
    private int m_end;

    /**
     * @param data
     */
    public void setBefore(String data) {
	this.m_before = data;
    }

    /**
     * @param data
     */
    public void setAfter(String data) {
	this.m_after = data;
    }

    /**
     * @param pos
     */
    public void setStart(int pos) {
	this.m_start = pos;
    }

    /**
     * @param pos
     */
    public void setEnd(int pos) {
	this.m_end = pos;
    }

    /**
     * @return
     */
    public String getBefore() {
	return this.m_before;
    }

    /**
     * @return
     */
    public String getAfter() {
	return this.m_after;
    }

    /**
     * @return
     */
    public int getStart() {
	return this.m_start;
    }

    /**
     * @return
     */
    public int getEnd() {
	return this.m_end;
    }

    /**
     * @return
     */
    public Object saveToMemento() {
	return new Memento(m_before, m_after, m_start, m_end);
    }

    /**
     * @param m
     */
    public void restoreFromMemento(Object m) {
	if (m instanceof Memento) {
	    Memento memento = (Memento) m;
	    m_before = memento.getSavedBefore();
	    m_after = memento.getSavedAfter();
	    m_start = memento.getSavedStart();
	    m_end = memento.getSavedEnd();
	}
    }

    private class Memento {

	private String m_before;
	private String m_after;
	private int m_start;
	private int m_end;

	/**
	 * @param before
	 * @param after
	 * @param start
	 * @param end
	 */
	public Memento(String before, String after, int start, int end) {
	    m_before = before;
	    m_after = after;
	    m_start = start;
	    m_end = end;
	}

	/**
	 * @return
	 */
	public String getSavedBefore() {
	    return this.m_before;
	}

	/**
	 * @return
	 */
	public String getSavedAfter() {
	    return this.m_after;
	}

	/**
	 * @return
	 */
	public int getSavedStart() {
	    return this.m_start;
	}

	/**
	 * @return
	 */
	public int getSavedEnd() {
	    return this.m_end;
	}
    }
}
